/**
 * Created by Administrator on 2017/4/26.
 */
/**
 * Created by Administrator on 2017/4/26.
 */
app.controller('commenVedioCtr',
    ['$scope','$location','$routeParams','$http','$sce','$rootScope', function ($scope,$location,$routeParams,$http,$sce,$rootScope) {
        /***
         * 视频评论
         * */
        var articleId =$routeParams.fileId;
        console.log("comId")
        console.log(articleId)
        // var articleId=174;
        //获取最新评论  page=0开始;加载更多评论
        var compage=0;
        alert(articleId);
        //加载更多最新评论？？不是page是哪个参数？？
        $scope.LoadMoreCom=function () {
            compage++;

            $http.jsonp(articleCommentDataUrl+'id=3969&siteId=1&lastFileId=0&page='+compage+'&jsoncallback=JSON_CALLBACK'
            ).success(function(data,header,config,status){
                // 是否还有更多评论
                $scope.hasMorCom=data.hasMore;
                $scope.commenCon=$scope.commenCon.concat(data.list);
            }).error(function(data,header,config,status){

            });

        };

        /*//获取最新评论
        $scope.getNewCom=function () {
            console.log(compage);
            $http.jsonp(articleCommentDataUrl+'id=3969&siteId=1&lastFileId=&page=0&jsoncallback=JSON_CALLBACK'
            ).success(function(data,header,config,status){
                console.log("第一次");
                console.log(data);
                // 是否还有更多评论
                $scope.hasMorCom=data.hasMore;
                $scope.commenCon=data.list;
            }).error(function(data,header,config,status){

            });
        };

        // 加载详情页时先加载最新评论一次，顺序问题,不能放getNewCom方法前
        $scope.getNewCom();
        //获取 热门评论
        $scope.getHotCom=function () {
            $http.jsonp(HotCommentDetailUrl+'id='+articleId+'&siteID=&jsoncallback=JSON_CALLBACK'
            ).success(function(data,header,config,status){
                console.log(data);
                // 是否还有更多评论
                $scope.hasMorCom=data.hasMore;
                //获取评论
                $scope.commenCon=data.list;
            }).error(function(data,header,config,status){
            });
        };

        //回复评论
        $scope.replayCom=function (parentId,userName,ParentUserID) {
            // 提交评论使用
            $scope.parentId=parentId;
            $scope.userName=userName;
            $scope.ParentUserID=ParentUserID;
            $("#comInput").attr("placeholder","@"+userName+":");
        };

        // 发送评论，地址和登录的id未知
        $scope.sendCom=function () {
            var sendMesg=$("#comInput").val();
            // console.log(sendMesg);
            var logUserId=$scope.uid_fouNder;
            var LogUserName=$scope.username_fouNder;
            var logUserId = 10;
            var LogUserName = 'sss';
            var siteID = 1, rootID = articleId, parentID = $scope.parentId, parentUser = $scope.userName,
                parentUserID = $scope.ParentUserID, topic = $scope.detailData.title, userID = logUserId
                , userName = LogUserName, type = 0,content=sendMesg;

            //提交回复
            $.ajax({
                type: "post",
                url: sendDiscussData,
                data:{
                    "siteID": siteID,
                    "rootID": '3969',
                    "parentID": parentID,
                    "parentUser": parentUser,
                    "parentUserID": parentUserID,
                    "topic": topic,
                    "userID": userID,
                    "userName": userName,
                    "type": type,
                    "content":content,
                    "channel":1
                },
                dataType : "jsonp",
                jsonp: "jsoncallback",
                jsoncallback:"jsoncallback",
                success: function(data){
                    if(data){
                        console.log(data);
                        alert("评论成功！重新获取数据获取不到");
                        $scope.getNewCom();
                        console.log("发送内容为：");
                        console.log(sendMesg);
                        $("#comInput").val("");
                    }else{
                        alert("评论失败！1");
                    }

                },
                error: function(){
                    alert("评论失败！2");
                }
            });
        };
*/
        //获取视频详情评论数据
        $scope.getNewCom = function () {
            $http.jsonp(vedioDetailComm+'id='+articleId+'&type=0&start=0&count=20&source=0&jsoncallback=JSON_CALLBACK'
            ).success(function (data, header, config, status) {
                // 是否还有更多评论
                $scope.hasMorCom = data.hasMore;
                $scope.commenCon = data.list;
            }).error(function (data, header, config, status) {

            });
        };


        //回复评论
        $scope.replayCom=function (parentId,userName,ParentUserID) {
            // 提交评论使用
            $scope.parentId=parentId;
            $scope.userName=userName;
            $scope.ParentUserID=ParentUserID;
            $("#comInput").attr("placeholder","@"+userName+":");
        };


        // 发送评论，地址和登录的id未知
        $scope.sendCom=function () {
            var sendMesg=$("#comInput").val();
            console.log(sendMesg);
            var logUserId=$scope.uid_fouNder;
            var LogUserName=$scope.username_fouNder;
            var logUserId = 10;
            var LogUserName = 'sss';
            var siteID = 1, rootID = articleId, parentID = $scope.parentId, parentUser = $scope.userName,
                parentUserID = $scope.ParentUserID, topic = $scope.detailData.title, userID = logUserId
                , userName = LogUserName, type = 0,content=sendMesg;


            //提交回复
            $.ajax({
                type: "post",
                url:sendVedioDiscussData,
                data:{
                    "siteID": siteID,
                    "rootID": '3969',
                    "parentID": parentID,
                    "parentUser": parentUser,
                    "parentUserID": parentUserID,
                    "topic": topic,
                    "userID": userID,
                    "userName": userName,
                    "type": type,
                    "content":content,
                    "channel":1
                },
                dataType : "jsonp",
                jsonp: "jsoncallback",
                jsoncallback:"jsoncallback",
                success: function(data){
                    if(data){
                        console.log(data);
                        alert("评论成功！重新获取数据获取不到");
                        $scope.getNewCom();
                        console.log("发送内容为：");
                        console.log(sendMesg);
                        $("#comInput").val("");
                    }else{
                        alert("评论失败！1");
                    }

                },
                error: function(){
                    alert("评论失败！2");
                }
            });


        };

        //回到顶部
        $(".fiBtn").hide();
        $(window).on("scroll", function(){
            if($(window).scrollTop() >0){
                $(".fiBtn").show();
            }else{
                $(".fiBtn").hide();
            }
        });
        $scope.goBackTop=function () {
            $("body").animate({scrollTop: 0}, 300);
        };

    }])
